package com.bistu.notepad_zjr.util;

import android.text.TextUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeChange {
    //时间戳转字符串
    public static String timeToStr(long timestamp){
        SimpleDateFormat sdf=  new SimpleDateFormat(  "yyyy-MM-dd" );
        String timeStr = sdf.format(timestamp);
        return timeStr;
    }

    //字符串转时间戳
    public static Long strToTime(String str) throws ParseException {
        long time;
        if (TextUtils.isEmpty(str)){
            time = 0;
        }else{
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            time = simpleDateFormat.parse(str).getTime();
        }
        return time;
    }

    //当前时间转字符串
    public static String newTimeToStr() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        return simpleDateFormat.format(date);
    }

    //获取当前时间
}
